1 #include "ModeSelect.h"
3 #include "RescourceKeys.h"
4 #include "ScreenNames.h"
6 ModeSelect::ModeSelect(int* scrs
, FileIO
* fileIO
, ResourceMaster
* resourcePointer
)
13 hoverAddressOld
= false;
15 rsc
= resourcePointer
;
18 renderer
= rsc
->rendPtr
;
21 outlineAnimation
= new Animation(rsc
->gameAnimations
.at(WhiteBlueBG
));
22 animations
[0] = new Animation(fio
->loadSpecificZip("1_0.zip"));
23 animations
[1] = new Animation(fio
->loadSpecificZip("1_1.zip"));
24 font
= new Fonts(0, rsc
);
26 std::string hs
= std::to_string(fio
->loadScoreData(1, *screen
% 50));
28 highscore
= "Highscore: ----";
31 highscore
= "Highscore: " + hs
;
34 std::string hl
= std::to_string(fio
->loadScoreData(2, *screen
% 50));
36 highlife
= "Highlife: ----";
39 highlife
= "Highlife: " + hl
;
47 ModeSelect::~ModeSelect()
51 int ModeSelect::getGameMode() {
56 void ModeSelect::createFonts() {
57 int textSizeX
= font
->prcnt(0.20, 'x');
58 int textSizeY
= font
->prcnt(0.15, 'y');
59 int textAlignX
= font
->prcnt(0.10, 'x');
60 int offsetAlignX
= font
->prcnt(0.17, 'x');
61 int centerAlignX
= font
->prcnt(0.45, 'x');
64 font
->loadFont(SDL_Color
{ 100,100,100,00 }, rsc
->gameText
.at(GoalText
), 2);
66 else if (gameMode
== 1) {
67 font
->loadFont(SDL_Color
{ 100,100,100,00 }, rsc
->gameText
.at(ArcadeText
), 2);
69 else if (gameMode
== 2) {
70 font
->loadFont(SDL_Color
{ 100,100,100,00 }, rsc
->gameText
.at(LifeText
), 2);
73 textGoal
= font
->getTexture();
74 rectGoal
= { textAlignX
, font
->prcnt(0.03, 'y'), textSizeX
, textSizeY
};
78 font
->loadFont(SDL_Color
{ 100,100,100,00 }, rsc
->gameText
.at(SubGoalText
), 2);
79 rectSubGoal
= { offsetAlignX
, font
->prcnt(0.14, 'y'), textSizeX
, textSizeY
};
81 else if (gameMode
== 1) {
82 font
->loadFont(SDL_Color
{ 100,100,100,00 }, rsc
->gameText
.at(ArcadeGoalText
), 2);
83 rectSubGoal
= { offsetAlignX
, font
->prcnt(0.14, 'y'), textSizeX
* 4 , textSizeY
};
85 else if (gameMode
== 2) {
86 font
->loadFont(SDL_Color
{ 100,100,100,00 }, rsc
->gameText
.at(LifeGoalText
), 2);
87 rectSubGoal
= { offsetAlignX
, font
->prcnt(0.14, 'y'), textSizeX
* 3 , textSizeY
};
89 textSubGoal
= font
->getTexture();
91 font
->loadFont(SDL_Color
{ 255,255,255,00 }, rsc
->gameText
.at(ArcadeText
), 2);
92 textArcade
= font
->getTexture();
93 rectArcade
= { textAlignX
, font
->prcnt(0.27, 'y'), textSizeX
, textSizeY
};
95 font
->loadFont(SDL_Color
{ 100,100,100,00 }, highscore
, 2);
96 textHighScore
= font
->getTexture();
97 rectHighScore
= { offsetAlignX
, font
->prcnt(0.37, 'y'), textSizeX
, textSizeY
};
99 font
->loadFont(SDL_Color
{ 255,255,255,00 }, rsc
->gameText
.at(LifeText
), 2);
100 textLife
= font
->getTexture();
101 rectLife
= { textAlignX
, font
->prcnt(0.50, 'y'), textSizeX
, textSizeY
};
103 font
->loadFont(SDL_Color
{ 100,100,100,00 }, highlife
, 2);
104 textHighLife
= font
->getTexture();
105 rectHighLife
= { offsetAlignX
, font
->prcnt(0.60, 'y'), textSizeX
, textSizeY
};
108 font
->loadFont(SDL_Color
{ 100,100,100,00 }, rsc
->gameText
.at(StartText
), 2);
111 font
->loadFont(SDL_Color
{ 255,255,255,00 }, rsc
->gameText
.at(StartText
), 2);
113 textStart
= font
->getTexture();
114 rectStart
= { centerAlignX
, font
->prcnt(0.78, 'y'), font
->prcnt(0.266, 'x'), font
->prcnt(0.20, 'y') };
118 void ModeSelect::destroyFonts() {
119 SDL_DestroyTexture(textArcade
);
121 SDL_DestroyTexture(textHighScore
);
123 SDL_DestroyTexture(textLife
);
125 SDL_DestroyTexture(textHighLife
);
127 SDL_DestroyTexture(textGoal
);
129 SDL_DestroyTexture(textSubGoal
);
131 SDL_DestroyTexture(textStart
);
135 void ModeSelect::update() {
140 if (modeSelected
&& x
> rectStart
.x
&& x
< rectStart
.x
+ rectStart
.w
&& y
> rectStart
.y
&& y
< rectStart
.y
+ rectStart
.h
) {
143 else if (x
> rectLife
.x
&& x
< rectLife
.x
+ rectLife
.w
&& y
> rectLife
.y
&& y
< rectLife
.y
+ rectLife
.h
) {
146 else if (x
> rectArcade
.x
&& x
< rectArcade
.x
+ rectArcade
.w
&& y
> rectArcade
.y
&& y
< rectArcade
.y
+ rectArcade
.h
) {
150 if (mouseClicked
&& hoverStart
&& modeSelected
) {
153 else if (mouseClicked
&& hoverArcade
) {
159 else if (mouseClicked
&& hoverLife
) {
168 *screen
= LevelSelectScreen
;
171 void ModeSelect::play() {
173 hoverAddress
= &hoverStart
;
176 hoverAddress
= &hoverLife
;
179 hoverAddress
= &hoverArcade
;
181 if (mouseClicked
&& (hoverStart
|| hoverArcade
|| hoverLife
) && !playedOnceL
) {
182 rsc
->sptr
->playSFX(0);
185 else if (mouseClicked
&& playedOnceL
) {
191 if (!playedOnce
&& (hoverStart
|| hoverArcade
|| hoverLife
) || hoverAddress
!= hoverAddressOld
) {
192 rsc
->sptr
->playSFX(1);
195 else if (playedOnce
&& (hoverStart
|| hoverArcade
|| hoverLife
)) {
201 hoverAddressOld
= hoverAddress
;
203 void ModeSelect::render() {
204 SDL_RenderClear(renderer
);
206 SDL_RenderCopy(renderer
, rsc
->gameGraphics
.at(LangBGFake
), NULL
, NULL
);
209 SDL_RenderCopy(renderer
, outlineAnimation
->itterateAnimation(30), NULL
, &rectStart
);
211 else if (hoverLife
) {
212 SDL_RenderCopy(renderer
, outlineAnimation
->itterateAnimation(30), NULL
, &rectLife
);
214 else if (hoverArcade
) {
215 SDL_RenderCopy(renderer
, outlineAnimation
->itterateAnimation(30), NULL
, &rectArcade
);
218 SDL_RenderCopy(renderer
, textArcade
, NULL
, &rectArcade
);
219 SDL_RenderCopy(renderer
, textHighScore
, NULL
, &rectHighScore
);
220 SDL_RenderCopy(renderer
, textLife
, NULL
, &rectLife
);
221 SDL_RenderCopy(renderer
, textHighLife
, NULL
, &rectHighLife
);
222 SDL_RenderCopy(renderer
, textStart
, NULL
, &rectStart
);
223 SDL_RenderCopy(renderer
, textGoal
, NULL
, &rectGoal
);
224 SDL_RenderCopy(renderer
, textSubGoal
, NULL
, &rectSubGoal
);
226 SDL_RenderPresent(renderer
);
229 void ModeSelect::close() {
231 if (!mouseClickedR
) {
236 animations
.at(1)->destroyAnimation();
237 animations
.at(0)->destroyAnimation();
242 std::array
<Animation
*, 2> ModeSelect::getAnimations() {
246 bool ModeSelect::getSkip() {